package com.speily.example.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.speily.example.framework.aspectj.lang.annotation.Log;
import com.speily.example.framework.aspectj.lang.enums.BusinessType;
import com.speily.example.entity.BizBaseData;
import com.speily.example.service.IBizBaseDataService;
import com.speily.example.framework.web.controller.BaseController;
import com.speily.example.framework.web.domain.AjaxResult;
import com.speily.example.common.utils.poi.ExcelUtil;
import com.speily.example.framework.web.page.TableDataInfo;

/**
 * 基础数据Controller
 * 
 * @author SPL
 * @date 2020-05-06
 */
@RestController
@RequestMapping("/business/baseData")
public class BizBaseDataController extends BaseController {
    @Resource
    private IBizBaseDataService bizBaseDataService;

    /**
     * 查询基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('example:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizBaseData bizBaseData) {
        startPage();
        List<BizBaseData> list = bizBaseDataService.selectBizBaseDataList(bizBaseData);
        bizBaseDataService.list();
        return getDataTable(list);
    }

    /**
     * 获取基础数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('example:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(bizBaseDataService.getById(id));
    }

    /**
     * 新增基础数据
     */
    @PreAuthorize("@ss.hasPermi('example:data:add')")
    @Log(title = "基础数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizBaseData bizBaseData) {
        bizBaseDataService.save(bizBaseData);
        return AjaxResult.success();
    }

    /**
     * 修改基础数据
     */
    @PreAuthorize("@ss.hasPermi('example:data:edit')")
    @Log(title = "基础数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizBaseData bizBaseData) {
        bizBaseDataService.updateById(bizBaseData);
        return AjaxResult.success();
    }

    /**
     * 删除基础数据
     */
    @PreAuthorize("@ss.hasPermi('example:data:remove')")
    @Log(title = "基础数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        bizBaseDataService.removeByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 导出基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('example:data:export')")
    @Log(title = "基础数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizBaseData bizBaseData)
    {
        List<BizBaseData> list = bizBaseDataService.selectBizBaseDataList(bizBaseData);
        ExcelUtil<BizBaseData> util = new ExcelUtil<BizBaseData>(BizBaseData.class);
        return util.exportExcel(list, "data");
    }
}
